<?php
namespace app\common\controller;
use OSS\OssClient;
use OSS\Core\OssException;

class Oss{
	
	/*文件上传到oss*/
public function oss_upload($file,$fileName)
{
    // 尝试执行
    try {
        //实例化对象 将配置传入
        $ossClient = new \OSS\OssClient(get_config("alioss_access_key"),get_config("alioss_secret_key"),get_config("alioss_point"));
        //这里是有sha1加密 生成文件名 之后连接上后缀
        //执行阿里云上传
        $result = $ossClient->uploadFile(get_config("alioss_bucket"), $fileName, $file);
        $arr = [
            'img_url' => $result['info']['url'],
            'code' =>200
        ];
    } catch (OssException $e) {
        return ["code"=>404,"msg"=>$e->getMessage()];
    }

    return $arr;
}


public function long_oss_upload($file,$folder = '')
{
    // 尝试执行
    try {
        //实例化对象 将配置传入
        $ossClient = new \OSS\OssClient(get_config("alioss_access_key"),get_config("alioss_secret_key"),get_config("alioss_point"));
        //这里是有sha1加密 生成文件名 之后连接上后缀
        //执行阿里云上传
        $result = $ossClient->putObject(get_config("alioss_bucket"), $folder, $file);
        $arr = [
            'img_url' => $result['info']['url'],
            'code' =>200
        ];
    } catch (OssException $e) {
        return ["code"=>404,"msg"=>$e->getMessage()];
    }

    return $arr;
}

}

?>